﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Common;
namespace xx
{
	/// <summary>
    /// 
    /// </summary>
	public class Bullet : MonoBehaviour,IResetable {
        public float moveSpeed = 10;
        private Vector3 targetPos;

        public void OnRest()
        {
            CalculateTargetPositon();
        }

        private void Awake()
        {
            
            //CalculateTargetPositon();
        }
        //计算目标方向
        private void CalculateTargetPositon()
        {
            //targetPos = transform.TransformPoint(0, 0, 100);//自身坐标系转换为世界坐标系
            targetPos = transform.position + transform.rotation * new Vector3(0, 0, 100);//等效于上面代码,强大灵活
        }

        private void Update()
        {
            print("targetPos222" + targetPos);
            transform.position = Vector3.MoveTowards(transform.position, targetPos, Time.deltaTime * moveSpeed);
            if (Vector3.Distance(transform.position,targetPos) < 0.1f)
            {//如果到达目标点，则销毁子弹
             //Destroy(gameObject);
                GameObjectPool.Instance.CollectObject(gameObject);
            }
        }
        
    }
}

